#!/bin/sh
# PCP QA Test No. 710
# Exercise python PMI layer using a real script
#
# Copyright (c) 2012,2022 Red Hat.
#

seq=`basename $0`
echo "QA output created by $seq"

. ./common.python

status=1	# failure is the default!
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15

$python -c 'from pcp import pmi' 2>/dev/null
test $? -eq 0 || _notrun 'Python pcp pmi module is not installed'

filter_dump()
{
    _filter_pmdumplog | \
	sed -e 's/value 0\.[0-9][0-9]*$/value DOUBLE/g'
}

# real QA test starts here
echo && echo "=== Check import v2"
$python $here/src/check_import.py $tmp.pcplog >$tmp.out 2>&1
if [ $? -eq 0 ]
then
    echo "=== logcheck ==="
    pmlogcheck $tmp.pcplog

    echo
    echo "=== dumplog ==="
    pmdumplog -dilmst $tmp.pcplog 2>&1 | filter_dump

    cat $tmp.out >>$seq_full
    echo "---" >>$seq_full
    pmdumplog -Dlog -a $tmp.pcplog >>$seq_full 2>&1
else
    cat $tmp.out
    echo "check_import python script gave non-zero result"
fi

# same again but for version 3 archive format
echo && echo "=== Check import v3"
$python $here/src/check_import.py $tmp.pcplog3 3 >$tmp.out 2>&1
if [ $? -eq 0 ]
then
    echo "=== logcheck ==="
    pmlogcheck $tmp.pcplog3

    echo
    echo "=== dumplog ==="
    pmdumplog -dilmst $tmp.pcplog3 2>&1 | filter_dump
    pmdumplog -a $tmp.pcplog3 >>$seq_full
else
    cat $tmp.out
    echo "check_import python script gave non-zero result for v3"
fi

# success, all done
status=$?
exit
